<!-- 调研分配 -->
<template>

	<ListLayout>

		<Card>
			<template #head>
				需求分配
			</template>
			<template #body>
				<evan-form :model="formData" ref="form">
					<evan-form-item label="调研负责人" prop="principal">
						<ItemRow v-model="formData.principal" chooseType="select-user"></ItemRow>
					</evan-form-item>
					<evan-form-item label="调研成员">
						<ItemRow v-model="formData.users" chooseType="select-user-multiple"></ItemRow>
					</evan-form-item>

				</evan-form>
			</template>
		</Card>
		<template #footer>
			<HButtonGroup @leftClick="leftClick" @rightClick="rightClick">
				<template #left>
					取消
				</template>
				<template #right>
					确认分配
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>

</template>
<script>
	import Card from '@/components/card/components/cardBaseWrapper.vue'
	import ListLayout from '@/components/layout/listLayout.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import ItemRow from '@/components/arrow/itemArrow.vue'
	import ProjectApi from '@/apis/project.js'
	import PagesDemandRouterConfig from '@/pagesDemand/routerConfig.js'
	export default {
		components: {
			Card,
			ListLayout,
			HButtonGroup,
			ItemRow,
		},
		onLoad(query) {
			this.routerParams.itemCode = query.itemCode
		},
		onReady() {
			this.$nextTick(() => {

				this.$refs.form.setRules(this.rules)
			})
		},
		data() {
			return {
				routerParams: {
					itemCode: ''
				},
				rules: {
					principal: [{
						required: true,
						message: '请选择调研负责人',
					}],
				},
				formData: {
					principal: '',
					users: '',
				},

			}
		},
		methods: {
			leftClick() {
				wx.navigateBack()
			},
			rightClick() {
				this.$refs['form'].validate(async (valid) => {

					if (valid) {
						let params = {
							itemCode: this.routerParams.itemCode,
							principal: this.formData.principal,
							users: this.formData.users,
						};
						await ProjectApi.Demand.Distribute(params)
						wx.showToast({
							title: '提交成功',
							complete() {
								wx.redirectTo({
									url: PagesDemandRouterConfig.Demand
								})
							}
						})

					}
				})

			},

		}
	}
</script>
